#include "../include/CServer.h"
#include "../include/conf_reader.h"
#include <boost/log/trivial.hpp>
#include <iostream>
#include "../include/Log.h"

#include <thread>
int main()
{
    init_logging();
    boost::asio::io_context context_for_CServer;
    //从配置文件中读取port
    int port=atoi(conf_reader::get_conf_reader_instance()->get_value_from_key("port","13456"));
    std::cout<<"该文件服务监听的端口为："<<port<<std::endl;
    std::shared_ptr<CServer>server(new CServer(context_for_CServer,port));
    server->start_accept();

    boost::asio::signal_set signals(context_for_CServer,SIGINT,SIGTERM);
    signals.async_wait([&context_for_CServer](const boost::system::error_code& error, int signal_number){
        if(error){
            std::cout<<"信号触发发生异常！！"<<error.what()<<std::endl; //几乎不可能发生
        }
        boost::log::core::get()->flush();
        context_for_CServer.stop();
    });

    context_for_CServer.run();
    
   


    

   


    return 0;
}